package me.send.business.service.mapper;

import java.util.List;
import java.util.Map;

import me.send.business.service.pojo.Advert;

import org.apache.ibatis.annotations.Result;
import org.apache.ibatis.annotations.Results;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;


public abstract interface AdvertMapper {
	
	// 查询首页的广告 2015年6月2日09:57:47
	@Select(value="select * from advert where status = 1 AND isdelete=0 AND (cityname=#{cityname} OR cityname='全国') AND endtime>#{currentDate} order by ordernumber,createtime")
	public abstract List<Advert> list(Map<String, Object> p1);
	
	@Select(value="SELECT * FROM advert a WHERE a.advertid=#{advertid}")
	@Results({
		@Result(column="original_price",property="originalPrice"),
		@Result(column="discount_price",property="discountPrice")
	})
	public abstract Advert getAdvertById(int advertid);
	
	/**
	 * 禁用广告
	 * @return
	 * @author maxmin
	 * @date 2015年9月24日上午9:47:23
	 */
	@Update(value="UPDATE advert SET status=0 WHERE type=1")
	public abstract int updateAdvertStatusOfAll();
	
	@Select(value="SELECT COUNT(1) FROM orders o WHERE o.advert_id=#{advertId} AND STR_TO_DATE(o.createtime,'%Y-%m-%d')=#{date} AND o.userid = #{userId} AND o.isdelete=0")
	int checkIsDiscounted(Map<String, Object> params);
}	
